# -*- coding: utf-8 -*-



## ------------------------------------------------------------
## Copyright 2010 Pierre-Antoine Delsart
## 
## This file is part of LeVin.
## 
## LeVin is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## 
## LeVin is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with LeVin.  If not, see <http://www.gnu.org/licenses/>.
## ---------------------------------------------------------------


from PythonQt import QtCore, QtGui
import qtcommon
import components
getData = qtcommon.getData


class AreaWidget(components.Component):
    class Dummy:
        def setVisible(self,a):
            pass
    def __init__(self, ):
        pass
    def setup(self):
        self.areaWid = QtGui.QWidget(self.mainWindow.rightSideWid)
        self.areaWid.setVisible(False)
        self.mainWindow.rightSideLayout.addWidget(self.areaWid)

        self.layout=QtGui.QVBoxLayout(self.areaWid)
        self.mapDic = {}
        self.currentMap = AreaWidget.Dummy()

    def wineRowSelected(self,row):
        self.areaWid.setVisible(False)
    def countryRowSelected(self,row):
        self.showMap(row)
        self.areaWid.setVisible(True)
    def regionRowSelected(self,row):
        self.showMap(row)
        self.areaWid.setVisible(True)

    def showMap(self,row):
        area = row.area
        print ' areawid ---> ',area.fullId()
        mapW = self.getMap(area)
        if mapW == self.currentMap:
            return
        self.currentMap.setVisible(False)
        mapW.setVisible(True)
        self.currentMap = mapW
    def getMap(self, area):
        mapW = self.mapDic.get( area, None)
        if mapW :
            return mapW
        mapW = qtcommon.FixedWidthSVG(self.areaWid)
        self.layout.addWidget(mapW,0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop)
        #self.layout.addWidget(mapW,0,)
        mapW.load( getData(area.fullId()+'_vineyards.svg'))

        self.mapDic[area] = mapW
        return mapW
